package com.wy.sloth.receiver.handler;

import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.wy.sloth.core.SlothMsgHandler;

/**
 * 测试消息处理
 * 
 * @author wangyuan
 * @since 2019年2月14日
 */
@Component
public class TestSyncHandler implements SlothMsgHandler {
    
    private static final Logger logger = LoggerFactory.getLogger(TestSyncHandler.class);

    @Override
    public JSONObject handle(JSONObject data) {
        logger.info("接收到的数据为：{}", data);
        long sleep = data.getLongValue("sleepSecond");
        Boolean exception = data.getBoolean("exception");
        try {
            TimeUnit.SECONDS.sleep(sleep);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        
        if(exception){
            throw new NullPointerException("人为抛异常");
        }
        
        JSONObject data1 = new JSONObject();
        data1.put("keyq", "1222222222");
        
        return data1;
    }

}
